<!doctype html>
<html lang="en">
	<head>
		<title>three.js canvas - combo camera - orthographic + perspective</title>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
		<style>
			body {
				font-family: Monospace;
				background-color: #f0f0f0;
				margin: 0px;
				overflow: hidden;
				color: purple;
			}

			a {
				color: red;
			}
		</style>
	</head>
	<body>

		<script src="../build/Three.js"></script>
		<script src="js/Stats.js"></script>
        
		<script>

			var container, stats;
			var camera, scene, renderer;
			posxx=100;
			posyy=-350;
			poszz=250;
			init();
		    animate();
			function init() {

				container = document.createElement( 'div' );
				document.body.appendChild( container );

				camera = new THREE.CombinedCamera( window.innerWidth /2, window.innerHeight/2, 70, 1, 1000, -1000, 1000, 1000 );

				camera.position.x = 200;
				camera.position.y = 100;
				camera.position.z = 200;

				scene = new THREE.Scene();
				controls = new THREE.TrackballControls( camera );
				scene.add( camera );
				// Cubes
	
				var geometry = new THREE.CubeGeometry( 30, 30, 10 );
				var material = new THREE.MeshLambertMaterial( { color: 0xffffff, shading: THREE.FlatShading, overdraw: true } );
				var cube = new THREE.Mesh( geometry, material );
					scene.add(cube);
					var geometry = new THREE.CubeGeometry( 5, 50, 5 );
				    var material = new THREE.MeshLambertMaterial( { color: 0xff0000, shading: THREE.FlatShading, overdraw: true } );
					var cube1 = new THREE.Mesh( geometry, material );
					cube1.position.x = -50;
					cube1.position.y = -20;
					cube1.position.z = 75;
				    scene.add(cube1);
					
				

			

				// Lights

				//var ambientLight = new THREE.AmbientLight( Math.random() * 0x10 );
			//	scene.add( ambientLight );

				var directionalLight = new THREE.DirectionalLight(  .25*0xffffff );
				directionalLight.position.x = 0.5;
				directionalLight.position.y = 0.5;
				directionalLight.position.z = 0.5;
				directionalLight.position.normalize();
				scene.add( directionalLight );
			
				renderer = new THREE.CanvasRenderer();
				renderer.setSize( window.innerWidth, window.innerHeight );

				container.appendChild( renderer.domElement );

				stats = new Stats();
				stats.domElement.style.position = 'absolute';
				stats.domElement.style.top = '0px';
				container.appendChild( stats.domElement );

				window.addEventListener( 'resize', onWindowResize, false );

				function onWindowResize(){

					camera.setSize( window.innerWidth, window.innerHeight );
					camera.updateProjectionMatrix();

					renderer.setSize( window.innerWidth, window.innerHeight );

				}
				
				document.addEventListener('keydown', function(e)
        	   	{
					switch(e.keyCode)
					{
	
							case 37: // left
								/*	posxx-=1;
									posyy-=1;*/
									var res = collision(cube.position.x,cube.position.y,cube.position.z);
									if(!(res)){
									cube.position.x -= 1;
									}
									//scene.add(cube);

									break;
	
							case 38: // up
									//poszz-=1;
									cube.position.z -= 1;
									break;
	
							case 39: // right
									/*posxx+=1;
									posyy+=1;*/
									cube.position.x += 1;
									break;
	
							case 40: // down
									//poszz+=1;
									cube.position.z += 1;
									break;
									
							case 87: // down
									//poszz+=10;
									cube.position.y += 1;
									break;
							case 83: // down
									//poszz-=10;
									cube.position.y -= 1;
									break;
					};
				});


			}

			//

			function animate() {

				requestAnimationFrame( animate );

				render();
				stats.update();

			}

			function render() {

				var timer = Date.now() * 0.0001;
				/*camera.position.x = Math.cos( timer ) * 200;
				camera.position.z = Math.sin( timer ) * 200;
*/			//	console.log(camera.position.x+"==="+camera.position.y)
				/*camera.position.x = posxx;
				camera.position.y = posyy;
				camera.position.z = poszz;*/
				camera.position.x = 0;
				camera.position.y = 0;
				camera.lookAt( scene.position );
//controls.update();
				renderer.render( scene, camera );

			}
			
			function collision(possx,possy,possz){
				var x=(-50+15+5);
				var y=-20;
				var z=75;
				if((possx==x) || (possy==y)  || (possz==z)){
				 return true;	
				}
			}
			
			
		</script>

	</body>
</html>
